﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Globalization;

public partial class Publishers : System.Web.UI.Page
{
    public string cid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridView1.DataSource = CusSqlDataSource;
            GridView1.DataBind();
           
        }
    }
    protected override void InitializeCulture()
    {
        if (Session["CurrentCulture"] != null)
        {
            string lang = Session["CurrentCulture"].ToString();
            if (lang != null && lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);


            }
        }

    }
    protected void delete_Click(object sender, EventArgs e)
    {
       
        LinkButton lkb = (LinkButton)sender;
        string myid = lkb.ToolTip;
         DataSet ds = DB.getdata("Select * from products where puplisher_id = " + myid);
         if (ds.Tables[0].Rows.Count > 0)
         {
             //Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "alert('لا يمكن المسح حيث انه مرتبط بمنتجات');", true);
             ScriptManager.RegisterStartupScript(this.up1, this.GetType(), "reports", "alert('لا يمكن المسح حيث انه مرتبط بمنتجات');", true);
         }
         else
         {
             DB.DELETE("publishers", "int,id," + myid);
             GridView1.DataSource = CusSqlDataSource;
             GridView1.DataBind();
         }


    }
   
    protected void display_Click(object sender, EventArgs e)
    {
        LinkButton lk = (LinkButton)sender;
        string[] args = lk.CommandArgument.Split(',');

        
        CustomerInfo1.Country = args[0];
        CustomerInfo1.Email = args[4];
        try
        {
           CustomerInfo1.Longs = decimal.Parse(args[2]);
           CustomerInfo1.Lat =decimal.Parse(args[3]);
           
        }
        catch (Exception)
        {
            
           
        }
        
        
       

        GridViewRow gr = (GridViewRow)lk.NamingContainer;
        CustomerInfo1.CompanyName = ((Label)gr.FindControl("co")).Text;
        CustomerInfo1.ClientName = ((Label)gr.FindControl("website")).Text;

        CustomerInfo1.Address = ((Label)gr.FindControl("add")).Text;
        CustomerInfo1.City = ((Label)gr.FindControl("city")).Text;
        string[] phos = ((Label)gr.FindControl("phone")).Text.Split(',');
        CustomerInfo1.Tele1 = phos[0];
        CustomerInfo1.Tele2 = phos[1];
        displays.Visible = true;
        //foreach (GridViewRow row in GridView1.Rows)
        //{
        //    row.BackColor = System.Drawing.Color.Empty;
        //}
        //GridView1.Rows[gr.RowIndex].BackColor = Color.YellowGreen;



    }
    
   
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        search();
    }
    public void search()
    {

        if (searchfield.Text.Length != 0)
        {


            Label1.Text = "";

            DataSet ds;

            string loadsearch = DB.remove_spaces(searchfield.Text);

           
            if (DropDownList1.SelectedValue == "0")
            {
                ds = DB.quick_search("Publishers", loadsearch);
            }
            else
            {
                ds = DB.quick_search("Publishers", loadsearch, DropDownList1.SelectedValue);
            }

            if (ds.Tables[0].Rows.Count > 0)
            {


                GridView1.DataSource = ds.Tables[0];
                GridView1.DataBind();
                Label1.Visible = false; 

            }
            else
            {

                Label1.Visible = true; 

            }


        }
        else
        {

            Label1.Text = " من فضلك لا يجوز ترك هذا الحقل خاليا";
            Label1.Visible = true;
        }


    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    e.Row.Attributes.Add("onmouseover", "this.Mystyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFA8'");

        //    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.Mystyle");
        //}
    }





    protected void ImageButton1_Click(object sender, EventArgs e)
    {
        search();
    }
   
}
